package com.portal.sso.server.config;

import com.portal.sso.core.server.*;
import com.portal.sso.core.server.impl.JwtServerHanderImpl;
import com.portal.sso.core.server.impl.RequestServerHandlerImpl;
import com.portal.sso.core.server.impl.VerificationCodeServerImpl;
import com.portal.sso.server.impl.SimplePasswordEncodeServerImpl;
import com.portal.sso.server.impl.SimplePortalUserServer;
import com.portal.sso.server.impl.SimpleTokenManageImpl;
import com.portal.sso.server.processor.ServerWhitelistProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.data.redis.core.StringRedisTemplate;

@Configuration
public class ServerWhitelistConfig{
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    ServerWhitelistProcessor serverWhitelistProcessor;
    @Bean
    public RequestServerHandler requestServerHandler(){
        return new RequestServerHandlerImpl();
    }
    @Bean
    public JwtServerHander jwtServerHanderImpl(){
        return new JwtServerHanderImpl();
    }

    /*@Bean
    public AbstractTokenManage simpleTokenManageImpl(){
        AbstractTokenManage simpleTokenManageImpl = new SimpleTokenManageImpl(serverWhitelistProcessor);
        return simpleTokenManageImpl;
    }*/

    //使用jdbc时注释此配置
    @Bean
    @ConditionalOnClass(PortalUserServer.class)
    @DependsOn
    public PortalUserServer SimplePortalUserServer(){
        return new SimplePortalUserServer();
    }

    @Bean
    @ConditionalOnMissingBean(PasswordEncodeServer.class)
    @ConditionalOnClass(PasswordEncodeServer.class)
    public PasswordEncodeServer SimplePasswordEncodeServerImpl(){
        return new SimplePasswordEncodeServerImpl();
    }

    @Bean
    public VerificationCodeServer verificationCodeServer(){
        VerificationCodeServer bean = new VerificationCodeServerImpl(redisTemplate);
        return bean;
    }
}
